/**
 * 
 */
package br.embedded.socialapp.location;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * @author daniel
 *
 */
public class LocationHandler {

	
	public static double calculateDistance(Coordenates firstCoordenate, Coordenates secondCoordenate)
	{
		// instantiate the calculator
		GeodeticCalculator geoCalc = new GeodeticCalculator();

		// select a reference elllipsoid
		Ellipsoid reference = Ellipsoid.WGS84;

		GlobalCoordinates coordenate1 = new GlobalCoordinates(firstCoordenate.getLatitude(), firstCoordenate.getLongitude());
		GlobalCoordinates coordenate2 = new GlobalCoordinates(secondCoordenate.getLatitude(), secondCoordenate.getLongitude());

		// calculate the geodetic curve
		GeodeticCurve geoCurve = geoCalc.calculateGeodeticCurve(reference, coordenate1, coordenate2);
		double ellipseKilometers = geoCurve.getEllipsoidalDistance() / 1000.0;

		
		//System.out.printf("Ellipsoidal Distance: %1.2f kilometers \n", ellipseKilometers);
		
		return ellipseKilometers * 1000.0;
	}
}
